using UnityEngine;
using UnityEngine.UI;

public class Item : MonoBehaviour
{
    public ItemData itemData;
    public int onGridPositionX;//占用格子x坐标
    public int onGridPositionY;//占用格子y坐标
    public bool rotated = false;

    public int WIDTH{
        get{
            if(rotated == false){
                return itemData.width;
            }
            return itemData.height;
        }
    }

    public int HEIGHT{
        get{
            if(rotated == false){
                return itemData.height;
            }
            return itemData.width;
        }
    }

    public void Set(ItemData itemData)
    {
        this.itemData = itemData;
        GetComponent<Image>().sprite = itemData.itemIcon;

        //修改物品尺寸
        Vector2 size = new Vector2();
        size.x = itemData.width * ItemGrid.tileSizeWidth;
        size.y = itemData.height * ItemGrid.tileSizeHeight;
        GetComponent<RectTransform>().sizeDelta = size;
    }

    //旋转物品
    public void Rotate()
    {
        rotated = !rotated;
        transform.rotation = Quaternion.Euler(0, 0, rotated == true ? 90f : 0f);
    }
}